package cj.hrm.dao;


import cj.hrm.dao.provider.RecruitmentDynaSqlProvider;
import cj.hrm.entity.Recruitment;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
import java.util.Map;

import static cj.hrm.util.common.HrmConstants.*;


public interface RecruitmentDao {
	
	//动态查询招聘
		@SelectProvider(type= RecruitmentDynaSqlProvider.class,method="selectWhitParam")
		@Results({
			@Result(id=true,column="id",property="id"),
			@Result(column="jobtype",property="jobtype",
			one=@One(select="cj.hrm.dao.JobTypeDao.selectById",
			fetchType=FetchType.EAGER)),
			@Result(column="status",property="status",
			one=@One(select="cj.hrm.dao.RecruitmentStatusDao.selectById",
		fetchType=FetchType.EAGER))
		})
		List<Recruitment> selectByPage();
		//根据参数查询招聘总数
		@SelectProvider(type=RecruitmentDynaSqlProvider.class,method="count")
		public Integer count(Map<String, Object> params);
		//根据id查询招聘
		@Select("select * from "+RECRUITMENTTABLE+" where id = #{id}")
		@Results({
			@Result(id=true,column="id",property="id"),
			@Result(column="jobtype",property="jobtype",
			one=@One(select="cj.hrm.dao.JobTypeDao.selectById",
			fetchType=FetchType.EAGER)),
			@Result(column="status",property="status",
			one=@One(select="cj.hrm.dao.RecruitmentStatusDao.selectById",
		fetchType=FetchType.EAGER))
		})
		Recruitment selectRecruitmentById(Integer id);

		//根据参数动态查询招聘
		@SelectProvider(type=RecruitmentDynaSqlProvider.class,method="selectWhitParam1")
		@Results({
			@Result(id=true,column="id",property="id"),
			@Result(column="jobtype",property="jobtype",
			one=@One(select="cj.hrm.dao.JobTypeDao.selectById",
			fetchType=FetchType.EAGER)),
			@Result(column="status",property="status",
			one=@One(select="cj.hrm.dao.RecruitmentStatusDao.selectById",
		fetchType=FetchType.EAGER))
		})
		List<Recruitment> selectByPage1(Map<String, Object> params);
		//根据id删除招聘
		@Delete(" delete from "+RECRUITMENTTABLE+" where id = #{id} ")
		void deleteRecruitmentById(Integer id);

		
		
		@Select("select * from "+RECRUITMENTTABLE+" where content like CONCAT('%',#{content},'%')"
				+ "or jobtype =(select id from "+JOBTYPETABLE+" where name like CONCAT('%',#{content},'%'))"
				+ "or status =(select id from "+RECRUITMENTSTATUSTABLE+" where name like CONCAT('%',#{content},'%'))"
				+ "or peoplenum like CONCAT('%',#{content},'%')"
				+ "or enddate like CONCAT('%',#{content},'%')")
		@Results({
			@Result(id=true,column="id",property="id"),
			@Result(column="jobtype",property="jobtype",
			one=@One(select="cj.hrm.dao.JobTypeDao.selectById",
			fetchType=FetchType.EAGER)),
			@Result(column="status",property="status",
			one=@One(select="cj.hrm.dao.RecruitmentStatusDao.selectById",
		fetchType=FetchType.EAGER))
		})
		List<Recruitment> get_LikeList(String content);

		
		
		@Select("select count(*) from "+RECRUITMENTTABLE+" where content like CONCAT('%',#{content},'%')"
				+ "or jobtype =(select id from "+JOBTYPETABLE+" where name like CONCAT('%',#{content},'%'))"
				+ "or status =(select id from "+RECRUITMENTSTATUSTABLE+" where name like CONCAT('%',#{content},'%'))"
				+ "or peoplenum like CONCAT('%',#{content},'%')"
				+ "or enddate like CONCAT('%',#{content},'%')")
		Integer countRecruitment(String content);

		//动态插入招聘
		@SelectProvider(type=RecruitmentDynaSqlProvider.class,method="insertRecruitment")
		void insert_Recruitment(Recruitment recruitment);
		//动态修改招聘
		@SelectProvider(type=RecruitmentDynaSqlProvider.class,method="updateRecruitment")
		void update_Recruitment(Recruitment recruitment);

}
